# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[self.style = style
self._selected_kwargs = dict(vcenter='50%', hcenter='50%')
self._not_selected_kwargs = dict(vcenter='50%', hcenter='50%')
self._not_selected_widget, self._selected_widget = self._create()
self.widget = Container()
self.widget.add_child(self._not_selected_widget, name='item', visible=False, **self._not_selected_kwargs)
self.widget.add_child(self._selected_widget, name='selected_item', visible=False, **self._selected_kwargs)
self._create_marker()
self._selected = False
self._marked = False
self._position = None
self._edited = False
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7733acc>}
nname: 40
n 40(None)[self._set_selected(selected, animate=False)
self.set_marked(item.is_marked(), animate=False)
self._position = position
self._set_edited(False, animate=False)
return None
]:
	i: 12(), 39()
	o: 

nname: 39
n 39(None)[]:
	i: 0(f)
	o: 40()

nname: 12
n 12(None)[log.warn('Item is None -- calling destroy() instead.')
return self.destroy()
]:
	i: 0(t)
	o: 40()

nname: 0
n 0(item is None)[]:
	i: 
	o: 12(t), 39(f)

nname: 0
n 0(None)[if item is None:
	log.warn('Item is None -- calling destroy() instead.')
	return self.destroy()
self._set_selected(selected, animate=False)
self.set_marked(item.is_marked(), animate=False)
self._position = position
self._set_edited(False, animate=False)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772afac>}
nname: 26
n 26(None)[return self._not_selected_widget
]:
	i: 0&9(t), 19()
	o: 

nname: 19
n 19(None)[]:
	i: 0&9(f)
	o: 26()

nname: 0&9
n 0&9(self._selected and self._selected_widget)[]:
	i: 
	o: 19(f), 26(t)

nname: 0&9
n 0&9(None)[if not(self._selected and self._selected_widget):
	pass
return self._not_selected_widget
]:
	i: 
	o: 

self.nodes: {'0&9': <unpyclib.structure.node instance at 0xb772ab4c>}
nname: 26
n 26(None)[return self._not_selected_widget
]:
	i: 0&9(t), 19()
	o: 

nname: 19
n 19(None)[]:
	i: 0&9(f)
	o: 26()

nname: 0&9
n 0&9(self._selected and self._selected_widget)[]:
	i: 
	o: 19(f), 26(t)

nname: 0&9
n 0&9(None)[if not(self._selected and self._selected_widget):
	pass
return self._not_selected_widget
]:
	i: 
	o: 

self.nodes: {'0&9': <unpyclib.structure.node instance at 0xb772ac8c>}
nname: 132
n 132(None)[return None
]:
	i: 65(), 131()
	o: 

nname: 131
n 131(None)[]:
	i: 0(f)
	o: 132()

nname: 65
n 65(None)[marker = self.widget.get_obj_by_name('marker')
marker._end_callback = None
marker.animate('color', a=255, duration=duration)
marker.show()
]:
	i: 0(t)
	o: 132()

nname: 0
n 0(self._marked)[aw = self.active_widget
aw._end_callback = None
duration = self.style['duration']
aw.animate('color', a=255, duration=duration)
]:
	i: 
	o: 65(t), 131(f)

nname: 0
n 0(None)[aw = self.active_widget
aw._end_callback = None
duration = self.style['duration']
aw.animate('color', a=255, duration=duration)
if self._marked:
	marker = self.widget.get_obj_by_name('marker')
	marker._end_callback = None
	marker.animate('color', a=255, duration=duration)
	marker.show()
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb773328c>}
nname: 0
n 0(None)[aw = self.active_widget
aw._end_callback = None
duration = self.style['duration']
aw.animate('color', a=0, duration=duration, end_callback=aw.hide)
marker = self.widget.get_obj_by_name('marker')
marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772aeac>}
nname: 0
n 0(None)[self.set_marked(False, animate=False)
self.widget.hide()
self._selected = False
self._position = None
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772ad2c>}
nname: 77
n 77(None)[marker_offset = self.style['marker_offset']
self.widget.add_child(marker, name='marker', aspect=0, visible=False, width='0%', height=self.style['marker_size'][1], top=marker_offset[1], left=marker_offset[0])
return None
]:
	i: 38(), 54()
	o: 

nname: 54
n 54(None)[marker = Image(path, config.themes_dir + '/wybox/icons/mimetypes/')
]:
	i: 0&25(f)
	o: 77()

nname: 38
n 38(None)[marker = Image(path)
]:
	i: 0&25(t)
	o: 77()

nname: 0&25
n 0&25(path is not None and exists(path))[path = self.style['marker_image']
]:
	i: 
	o: 38(t), 54(f)

nname: 0&25
n 0&25(None)[path = self.style['marker_image']
if path is not None and exists(path):
	marker = Image(path)
else:
	marker = Image(path, config.themes_dir + '/wybox/icons/mimetypes/')
marker_offset = self.style['marker_offset']
self.widget.add_child(marker, name='marker', aspect=0, visible=False, width='0%', height=self.style['marker_size'][1], top=marker_offset[1], left=marker_offset[0])
return None
]:
	i: 
	o: 

self.nodes: {'0&25': <unpyclib.structure.node instance at 0xb77336ac>}
nname: 51
n 51(None)[duration = 0
marker.show()
marker.animate('size', width=self.style['marker_size'][0], duration=duration)
marker.animate('color', a=255, duration=duration)
return None
]:
	i: 33(), 47()
	o: 

nname: 47
n 47(None)[]:
	i: 0(f)
	o: 51()

nname: 33
n 33(None)[]:
	i: 0(t)
	o: 51()

nname: 0
n 0(animate)[marker = self.widget.get_obj_by_name('marker')
marker._end_callback = None
]:
	i: 
	o: 33(t), 47(f)

nname: 0
n 0(None)[marker = self.widget.get_obj_by_name('marker')
marker._end_callback = None
if animate:
	pass
duration = 0
marker.show()
marker.animate('size', width=self.style['marker_size'][0], duration=duration)
marker.animate('color', a=255, duration=duration)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772afac>}
nname: 51
n 51(None)[duration = 0
marker.animate('size', width='1%', duration=duration)
marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
return None
]:
	i: 33(), 47()
	o: 

nname: 47
n 47(None)[]:
	i: 0(f)
	o: 51()

nname: 33
n 33(None)[]:
	i: 0(t)
	o: 51()

nname: 0
n 0(animate)[marker = self.widget.get_obj_by_name('marker')
marker._end_callback = None
]:
	i: 
	o: 33(t), 47(f)

nname: 0
n 0(None)[marker = self.widget.get_obj_by_name('marker')
marker._end_callback = None
if animate:
	pass
duration = 0
marker.animate('size', width='1%', duration=duration)
marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772aacc>}
nname: 0
n 0(None)[return self._marked
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772a8cc>}
nname: 72
n 72(None)[]:
	i: 37(JA), 54(), 71()
	o: 

nname: 71
n 71(None)[]:
	i: 0(f)
	o: 72()

nname: 54
n 54(None)[self.unmark(animate)
]:
	i: 15(f)
	o: 72()

nname: 37
n 37(None)[self.mark(animate)
]:
	i: 15(t)
	o: 72(JA)

nname: 15
n 15(val)[self._marked = bool(val)
]:
	i: 0(t)
	o: 37(t), 54(f)

nname: 0
n 0(self._marked != val)[]:
	i: 
	o: 15(t), 71(f)

nname: 0
n 0(None)[if self._marked != val:
	self._marked = bool(val)
	if val:
		self.mark(animate)
	else:
		self.unmark(animate)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772aeac>}
nname: 114
n 114(None)[to_hide.hide()
to_show.show()
]:
	i: 33(), 75()
	o: 

nname: 75
n 75(None)[to_show = self._not_selected_widget
to_hide = self._selected_widget
marker.load(self.style['marker_image'])
]:
	i: 0(f)
	o: 114()

nname: 33
n 33(None)[to_show = self._selected_widget
to_hide = self._not_selected_widget
marker.load(self.style['selected_marker_image'])
]:
	i: 0(t)
	o: 114()

nname: 0
n 0(selected)[self._selected = selected
marker = self.widget.get_obj_by_name('marker')
]:
	i: 
	o: 33(t), 75(f)

nname: 0
n 0(None)[self._selected = selected
marker = self.widget.get_obj_by_name('marker')
if selected:
	to_show = self._selected_widget
	to_hide = self._not_selected_widget
	marker.load(self.style['selected_marker_image'])
else:
	to_show = self._not_selected_widget
	to_hide = self._selected_widget
	marker.load(self.style['marker_image'])
to_hide.hide()
to_show.show()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb77331ac>}
nname: 0
n 0(None)[return self._selected
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772a90c>}
nname: 0
n 0(None)[self._position = position
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772ac6c>}
nname: 58
n 58(None)[log.debug("%s doesn't exist", name)
return None
]:
	i: 0(AL), 57()
	o: 

nname: 57
n 57(None)[]:
	i: 13(AF), 53()
	o: 58()

nname: 53
n 53(None)[]:
	i: 20(f), 45()
	o: 57()

nname: 45
n 45(None)[return name
continue
]:
	i: 20(t)
	o: 53()

nname: 20
n 20(isfile(name))[for ext in extension:
name = _name + ext
]:
	i: 13(for)
	o: 45(t), 53(f)

nname: 13
n 13(None)[]:
	i: 0(loop)
	o: 20(for), 57(AF)

nname: 0
n 0(None)[_name = root + suf
]:
	i: 
	o: 13(loop), 58(AL)

nname: 58
n 58(None)[log.debug("%s doesn't exist", name)
return None
]:
	i: 0(AL), 13(AF), 20()
	o: 

nname: 20
n 20(None)[for ext in extension:
name = _name + ext
if isfile(name):
	return name
	continue
]:
	i: 13(for)
	o: 58()

nname: 13
n 13(None)[]:
	i: 0(loop)
	o: 20(for), 58(AF)

nname: 0
n 0(None)[_name = root + suf
]:
	i: 
	o: 13(loop), 58(AL)

nname: 20
n 20(None)[for ext in extension:
	name = _name + ext
	if isfile(name):
		return name
		continue
log.debug("%s doesn't exist", name)
return None
]:
	i: 0(for)
	o: 

nname: 0
n 0(None)[_name = root + suf
]:
	i: 
	o: 20(for)

nname: 0
n 0(None)[_name = root + suf
for ext in extension:
	name = _name + ext
	if isfile(name):
		return name
		continue
log.debug("%s doesn't exist", name)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb77338cc>}
nname: 93
n 93(None)[del _[1]
return ('.', '_selected.')
]:
	i: 0(AF), 74()
	o: 

nname: 74
n 74(None)[for suf in ('.', '_selected.'):
]:
	i: 0(for)
	o: 93()

nname: 0
n 0(None)[root = join(self.style['repository'], '%s' % item.display_type)
extension = self.style['extension']
def check_concat(suf):
	_name = root + suf
	for ext in extension:
		name = _name + ext
		if isfile(name):
			return name
			continue
	log.debug("%s doesn't exist", name)
	return None

]:
	i: 
	o: 74(for), 93(AF)

self.nodes: {0: <unpyclib.structure.node instance at 0xb772ad6c>, 74: <unpyclib.structure.node instance at 0xb772afcc>, 93: <unpyclib.structure.node instance at 0xb772abec>}
nname: 101
n 101(None)[duration = 0
self._selected_widget.animate('move', duration=duration, hcenter=move)
self._not_selected_widget.animate('move', duration=duration, hcenter=move)
]:
	i: 83(), 97()
	o: 

nname: 97
n 97(None)[]:
	i: 77(f)
	o: 101()

nname: 83
n 83(None)[]:
	i: 77(t)
	o: 101()

nname: 77
n 77(animate)[]:
	i: 39(), 70()
	o: 83(t), 97(f)

nname: 70
n 70(None)[move = '50%'
]:
	i: 24(f)
	o: 77()

nname: 39
n 39(None)[move = '%d%%' % int(50 + self.style['edit_offset'])
]:
	i: 24(t)
	o: 77()

nname: 24
n 24(edited)[self._edited = edited
]:
	i: 15(), 23()
	o: 39(t), 70(f)

nname: 23
n 23(None)[]:
	i: 0(f)
	o: 24()

nname: 15
n 15(None)[]:
	i: 0(t)
	o: 24()

nname: 0
n 0(self._edited == edited)[]:
	i: 
	o: 15(t), 23(f)

nname: 77
n 77(None)[if animate:
	pass
duration = 0
self._selected_widget.animate('move', duration=duration, hcenter=move)
self._not_selected_widget.animate('move', duration=duration, hcenter=move)
]:
	i: 0()
	o: 

nname: 0
n 0(None)[if self._edited == edited:
	pass
self._edited = edited
if edited:
	move = '%d%%' % int(50 + self.style['edit_offset'])
else:
	move = '50%'
]:
	i: 
	o: 77()

nname: 0
n 0(None)[if self._edited == edited:
	pass
self._edited = edited
if edited:
	move = '%d%%' % int(50 + self.style['edit_offset'])
else:
	move = '50%'
if animate:
	pass
duration = 0
self._selected_widget.animate('move', duration=duration, hcenter=move)
self._not_selected_widget.animate('move', duration=duration, hcenter=move)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb77338ec>}
nname: 0
n 0(None)[return self._edited
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772ad4c>}
nname: 6
n 6(None)[__slots__ = ['_selected', '_marked', '_position', '_edited', 'widget', 'style', '_not_selected_widget', '_selected_widget', '_selected_kwargs', '_not_selected_kwargs']
def __init__(self, style):
	self.style = style
	self._selected_kwargs = dict(vcenter='50%', hcenter='50%')
	self._not_selected_kwargs = dict(vcenter='50%', hcenter='50%')
	self._not_selected_widget, self._selected_widget = self._create()
	self.widget = Container()
	self.widget.add_child(self._not_selected_widget, name='item', visible=False, **self._not_selected_kwargs)
	self.widget.add_child(self._selected_widget, name='selected_item', visible=False, **self._selected_kwargs)
	self._create_marker()
	self._selected = False
	self._marked = False
	self._position = None
	self._edited = False
	return None

def reset(self, item, selected, position=None):
	if item is None:
		log.warn('Item is None -- calling destroy() instead.')
		return self.destroy()
	self._set_selected(selected, animate=False)
	self.set_marked(item.is_marked(), animate=False)
	self._position = position
	self._set_edited(False, animate=False)
	return None

active_widget = property((lambda self: self._selected and self._selected_widget):
	pass
return self._not_selected_widget), doc='Widget currently visible (selected or not)')
def fade_in(self):
	aw = self.active_widget
	aw._end_callback = None
	duration = self.style['duration']
	aw.animate('color', a=255, duration=duration)
	if self._marked:
		marker = self.widget.get_obj_by_name('marker')
		marker._end_callback = None
		marker.animate('color', a=255, duration=duration)
		marker.show()
	return None

def fade_out(self):
	aw = self.active_widget
	aw._end_callback = None
	duration = self.style['duration']
	aw.animate('color', a=0, duration=duration, end_callback=aw.hide)
	marker = self.widget.get_obj_by_name('marker')
	marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
	return None

def destroy(self):
	self.set_marked(False, animate=False)
	self.widget.hide()
	self._selected = False
	self._position = None
	return None

def _create_marker(self):
	path = self.style['marker_image']
	if path is not None and exists(path):
		marker = Image(path)
	else:
		marker = Image(path, config.themes_dir + '/wybox/icons/mimetypes/')
	marker_offset = self.style['marker_offset']
	self.widget.add_child(marker, name='marker', aspect=0, visible=False, width='0%', height=self.style['marker_size'][1], top=marker_offset[1], left=marker_offset[0])
	return None

def mark(self, animate):
	marker = self.widget.get_obj_by_name('marker')
	marker._end_callback = None
	if animate:
		pass
	duration = 0
	marker.show()
	marker.animate('size', width=self.style['marker_size'][0], duration=duration)
	marker.animate('color', a=255, duration=duration)
	return None

def unmark(self, animate):
	marker = self.widget.get_obj_by_name('marker')
	marker._end_callback = None
	if animate:
		pass
	duration = 0
	marker.animate('size', width='1%', duration=duration)
	marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
	return None

def get_marked(self):
	return self._marked

def set_marked(self, val, animate=True):
	if self._marked != val:
		self._marked = bool(val)
		if val:
			self.mark(animate)
		else:
			self.unmark(animate)

marked = property(get_marked, set_marked, doc='Set the marker status on this item')
del get_marked
def _set_selected(self, selected, animate=True):
	self._selected = selected
	marker = self.widget.get_obj_by_name('marker')
	if selected:
		to_show = self._selected_widget
		to_hide = self._not_selected_widget
		marker.load(self.style['selected_marker_image'])
	else:
		to_show = self._not_selected_widget
		to_hide = self._selected_widget
		marker.load(self.style['marker_image'])
	to_hide.hide()
	to_show.show()

def _get_selected(self):
	return self._selected

selected = late_property(_get_selected, _set_selected, doc='Set the selected status on this item')
def set_position(self, position):
	self._position = position

def _get_images_paths(self, item):
	root = join(self.style['repository'], '%s' % item.display_type)
	extension = self.style['extension']
	def check_concat(suf):
		_name = root + suf
		for ext in extension:
			name = _name + ext
			if isfile(name):
				return name
				continue
		log.debug("%s doesn't exist", name)
		return None


def _set_edited(self, edited, animate=True):
	if self._edited == edited:
		pass
	self._edited = edited
	if edited:
		move = '%d%%' % int(50 + self.style['edit_offset'])
	else:
		move = '50%'
	if animate:
		pass
	duration = 0
	self._selected_widget.animate('move', duration=duration, hcenter=move)
	self._not_selected_widget.animate('move', duration=duration, hcenter=move)

def _get_edited(self):
	return self._edited

edited = late_property(_get_edited, _set_edited)
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb7727bac>}
nname: 0
n 0(None)[from __future__ import absolute_import
from os.path import exists, join, isfile
from peewee.misc_utils import late_property
from peewee.debug import GET_LOGGER
from wyvas import Image, Container
import pygui.config as config
log = GET_LOGGER(__name__)
class UIItem(object):
	__slots__ = ['_selected', '_marked', '_position', '_edited', 'widget', 'style', '_not_selected_widget', '_selected_widget', '_selected_kwargs', '_not_selected_kwargs']
	def __init__(self, style):
		self.style = style
		self._selected_kwargs = dict(vcenter='50%', hcenter='50%')
		self._not_selected_kwargs = dict(vcenter='50%', hcenter='50%')
		self._not_selected_widget, self._selected_widget = self._create()
		self.widget = Container()
		self.widget.add_child(self._not_selected_widget, name='item', visible=False, **self._not_selected_kwargs)
		self.widget.add_child(self._selected_widget, name='selected_item', visible=False, **self._selected_kwargs)
		self._create_marker()
		self._selected = False
		self._marked = False
		self._position = None
		self._edited = False
		return None

	def reset(self, item, selected, position=None):
		if item is None:
			log.warn('Item is None -- calling destroy() instead.')
			return self.destroy()
		self._set_selected(selected, animate=False)
		self.set_marked(item.is_marked(), animate=False)
		self._position = position
		self._set_edited(False, animate=False)
		return None

	active_widget = property((lambda self: self._selected and self._selected_widget):
		pass
	return self._not_selected_widget), doc='Widget currently visible (selected or not)')
	def fade_in(self):
		aw = self.active_widget
		aw._end_callback = None
		duration = self.style['duration']
		aw.animate('color', a=255, duration=duration)
		if self._marked:
			marker = self.widget.get_obj_by_name('marker')
			marker._end_callback = None
			marker.animate('color', a=255, duration=duration)
			marker.show()
		return None

	def fade_out(self):
		aw = self.active_widget
		aw._end_callback = None
		duration = self.style['duration']
		aw.animate('color', a=0, duration=duration, end_callback=aw.hide)
		marker = self.widget.get_obj_by_name('marker')
		marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
		return None

	def destroy(self):
		self.set_marked(False, animate=False)
		self.widget.hide()
		self._selected = False
		self._position = None
		return None

	def _create_marker(self):
		path = self.style['marker_image']
		if path is not None and exists(path):
			marker = Image(path)
		else:
			marker = Image(path, config.themes_dir + '/wybox/icons/mimetypes/')
		marker_offset = self.style['marker_offset']
		self.widget.add_child(marker, name='marker', aspect=0, visible=False, width='0%', height=self.style['marker_size'][1], top=marker_offset[1], left=marker_offset[0])
		return None

	def mark(self, animate):
		marker = self.widget.get_obj_by_name('marker')
		marker._end_callback = None
		if animate:
			pass
		duration = 0
		marker.show()
		marker.animate('size', width=self.style['marker_size'][0], duration=duration)
		marker.animate('color', a=255, duration=duration)
		return None

	def unmark(self, animate):
		marker = self.widget.get_obj_by_name('marker')
		marker._end_callback = None
		if animate:
			pass
		duration = 0
		marker.animate('size', width='1%', duration=duration)
		marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
		return None

	def get_marked(self):
		return self._marked

	def set_marked(self, val, animate=True):
		if self._marked != val:
			self._marked = bool(val)
			if val:
				self.mark(animate)
			else:
				self.unmark(animate)

	marked = property(get_marked, set_marked, doc='Set the marker status on this item')
	del get_marked
	def _set_selected(self, selected, animate=True):
		self._selected = selected
		marker = self.widget.get_obj_by_name('marker')
		if selected:
			to_show = self._selected_widget
			to_hide = self._not_selected_widget
			marker.load(self.style['selected_marker_image'])
		else:
			to_show = self._not_selected_widget
			to_hide = self._selected_widget
			marker.load(self.style['marker_image'])
		to_hide.hide()
		to_show.show()

	def _get_selected(self):
		return self._selected

	selected = late_property(_get_selected, _set_selected, doc='Set the selected status on this item')
	def set_position(self, position):
		self._position = position

	def _get_images_paths(self, item):
		root = join(self.style['repository'], '%s' % item.display_type)
		extension = self.style['extension']
		def check_concat(suf):
			_name = root + suf
			for ext in extension:
				name = _name + ext
				if isfile(name):
					return name
					continue
			log.debug("%s doesn't exist", name)
			return None


	def _set_edited(self, edited, animate=True):
		if self._edited == edited:
			pass
		self._edited = edited
		if edited:
			move = '%d%%' % int(50 + self.style['edit_offset'])
		else:
			move = '50%'
		if animate:
			pass
		duration = 0
		self._selected_widget.animate('move', duration=duration, hcenter=move)
		self._not_selected_widget.animate('move', duration=duration, hcenter=move)

	def _get_edited(self):
		return self._edited

	edited = late_property(_get_edited, _set_edited)


]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb771f52c>}
from __future__ import absolute_import
from os.path import exists, join, isfile
from peewee.misc_utils import late_property
from peewee.debug import GET_LOGGER
from wyvas import Image, Container
import pygui.config as config
log = GET_LOGGER(__name__)
class UIItem(object):
	__slots__ = ['_selected', '_marked', '_position', '_edited', 'widget', 'style', '_not_selected_widget', '_selected_widget', '_selected_kwargs', '_not_selected_kwargs']
	def __init__(self, style):
		self.style = style
		self._selected_kwargs = dict(vcenter='50%', hcenter='50%')
		self._not_selected_kwargs = dict(vcenter='50%', hcenter='50%')
		self._not_selected_widget, self._selected_widget = self._create()
		self.widget = Container()
		self.widget.add_child(self._not_selected_widget, name='item', visible=False, **self._not_selected_kwargs)
		self.widget.add_child(self._selected_widget, name='selected_item', visible=False, **self._selected_kwargs)
		self._create_marker()
		self._selected = False
		self._marked = False
		self._position = None
		self._edited = False
		return None

	def reset(self, item, selected, position=None):
		if item is None:
			log.warn('Item is None -- calling destroy() instead.')
			return self.destroy()
		self._set_selected(selected, animate=False)
		self.set_marked(item.is_marked(), animate=False)
		self._position = position
		self._set_edited(False, animate=False)
		return None

	active_widget = property((lambda self: self._selected and self._selected_widget):
		pass
	return self._not_selected_widget), doc='Widget currently visible (selected or not)')
	def fade_in(self):
		aw = self.active_widget
		aw._end_callback = None
		duration = self.style['duration']
		aw.animate('color', a=255, duration=duration)
		if self._marked:
			marker = self.widget.get_obj_by_name('marker')
			marker._end_callback = None
			marker.animate('color', a=255, duration=duration)
			marker.show()
		return None

	def fade_out(self):
		aw = self.active_widget
		aw._end_callback = None
		duration = self.style['duration']
		aw.animate('color', a=0, duration=duration, end_callback=aw.hide)
		marker = self.widget.get_obj_by_name('marker')
		marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
		return None

	def destroy(self):
		self.set_marked(False, animate=False)
		self.widget.hide()
		self._selected = False
		self._position = None
		return None

	def _create_marker(self):
		path = self.style['marker_image']
		if path is not None and exists(path):
			marker = Image(path)
		else:
			marker = Image(path, config.themes_dir + '/wybox/icons/mimetypes/')
		marker_offset = self.style['marker_offset']
		self.widget.add_child(marker, name='marker', aspect=0, visible=False, width='0%', height=self.style['marker_size'][1], top=marker_offset[1], left=marker_offset[0])
		return None

	def mark(self, animate):
		marker = self.widget.get_obj_by_name('marker')
		marker._end_callback = None
		if animate:
			pass
		duration = 0
		marker.show()
		marker.animate('size', width=self.style['marker_size'][0], duration=duration)
		marker.animate('color', a=255, duration=duration)
		return None

	def unmark(self, animate):
		marker = self.widget.get_obj_by_name('marker')
		marker._end_callback = None
		if animate:
			pass
		duration = 0
		marker.animate('size', width='1%', duration=duration)
		marker.animate('color', a=0, duration=duration, end_callback=marker.hide)
		return None

	def get_marked(self):
		return self._marked

	def set_marked(self, val, animate=True):
		if self._marked != val:
			self._marked = bool(val)
			if val:
				self.mark(animate)
			else:
				self.unmark(animate)

	marked = property(get_marked, set_marked, doc='Set the marker status on this item')
	del get_marked
	def _set_selected(self, selected, animate=True):
		self._selected = selected
		marker = self.widget.get_obj_by_name('marker')
		if selected:
			to_show = self._selected_widget
			to_hide = self._not_selected_widget
			marker.load(self.style['selected_marker_image'])
		else:
			to_show = self._not_selected_widget
			to_hide = self._selected_widget
			marker.load(self.style['marker_image'])
		to_hide.hide()
		to_show.show()

	def _get_selected(self):
		return self._selected

	selected = late_property(_get_selected, _set_selected, doc='Set the selected status on this item')
	def set_position(self, position):
		self._position = position

	def _get_images_paths(self, item):
		root = join(self.style['repository'], '%s' % item.display_type)
		extension = self.style['extension']
		def check_concat(suf):
			_name = root + suf
			for ext in extension:
				name = _name + ext
				if isfile(name):
					return name
					continue
			log.debug("%s doesn't exist", name)
			return None


	def _set_edited(self, edited, animate=True):
		if self._edited == edited:
			pass
		self._edited = edited
		if edited:
			move = '%d%%' % int(50 + self.style['edit_offset'])
		else:
			move = '50%'
		if animate:
			pass
		duration = 0
		self._selected_widget.animate('move', duration=duration, hcenter=move)
		self._not_selected_widget.animate('move', duration=duration, hcenter=move)

	def _get_edited(self):
		return self._edited

	edited = late_property(_get_edited, _set_edited)


